package com.zkjl.protect_business.utils;

import cn.hutool.crypto.digest.DigestAlgorithm;
import cn.hutool.crypto.digest.Digester;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

public class MD5Util {

    private static Digester md5 = new Digester(DigestAlgorithm.MD5);


    /**
     * 获取文件摘要
     * @param file
     * @return
     * @throws IOException
     */
    public static String digestHex(MultipartFile file) throws IOException {

        byte[] bytes = file.getBytes();

        String hash = md5.digestHex(bytes);

        return hash;
    }


    /**
     * 获取文件摘要
     * @param file
     * @return
     */
    public static String digestHex(File file) {
        String hash = md5.digestHex(file);
        return hash;
    }

    /**
     * 获取文件摘要
     * @param bytes
     * @return
     */
    public static String digestHex(byte[] bytes) {
        String hash = md5.digestHex(bytes);
        return hash;
    }

}
